package com.max.mil.fuwu.controller;

import java.util.Date;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.max.mil.common.util.DataPage;
import com.max.mil.fuwu.model.Promotion;
import com.max.mil.fuwu.model.vo.Prod;
import com.max.mil.fuwu.service.ProdService;
import com.max.mil.fuwu.service.PromotionService;
import com.max.mil.fuwu.service.impl.ProdServiceImpl;
import com.max.mil.fuwu.service.impl.PromotionServiceImpl;

@Controller
@RequestMapping("/prom")
public class PromController
{

	ProdService prodService = new ProdServiceImpl();
	
	PromotionService promService = new PromotionServiceImpl();
	
	
	@RequestMapping("/promList")
	public String promList(int type, int status, int pageNo, int pageSize, Model model) throws Exception 
	{
		DataPage<Promotion> dp = promService.getPromotion(type, status, pageNo, pageSize);
		model.addAttribute("dp", dp);
		
		return "prom/promList";
	}
	
	
	/**=========================================价格促销开始==========================================*/
	@RequestMapping("/saleTempPre")
	public String saleTempPre(Integer promId, Model model) throws Exception 
	{
		
		return "prom/saleTemp";
	}
	
	@RequestMapping("/saleTemp")
	public String saleTemp(Integer promId, String name, Date effectTime, Date expireTime, Model model) throws Exception 
	{
		Promotion prom = new Promotion();
		prom.setType(1);
		prom.setName(name);
		prom.setContent(null);
		prom.setStatus(1);
		prom.setEffectTime(effectTime);
		prom.setExpireTime(expireTime);
		prom.setCreateTime(new Date());
		prom.setModifyTime(prom.getCreateTime());
		int id = promService.addPromotion(prom);
		
		model.addAttribute("promId", id);
		return "redirect:saleItemPre.do?promId={promId}";
	}
	
	@RequestMapping("/saleItemPre")
	public String saleItemPre(Integer promId, Model model) throws Exception 
	{
//		DataPage<Prod> dp = prodService.getProdList(null, null, null, null, 15, 1, 10);
//		model.addAttribute("dp", dp);
		
		return "prom/saleItem";
	}
	/**=========================================价格促销结束==========================================*/
}
